<!--suppress ALL -->
<include file="./Template/header.html" />

<link rel="stylesheet" type="text/css" href="/Template/css/finishedOrder.css?v=2020073101">
<link rel="stylesheet" type="text/css" href="/Template/css/measure.css">
<script type="text/javascript" src="/Template/js/amazeui.js"></script>
<script type="text/javascript">


    $(function() {

        //初始化页面配置
        initPage("订单确认");

        var app = new Vue({
            el: '#container',
            data: {
                number: "{$groupOrder.number}",
                singlePrice: "{$product.group_price}",
            },
            methods: {
				createOrder: function(status) {
                    var productId = "{$product.product_id}";
                    var size = $("select[name=size]").val();
                    var receiveName = $("input[name=receiveName]").val();
                    var receiveContact = $("input[name=receiveContact]").val();
                    var receiveAddress = $("input[name=receiveAddress]").val();
                    var patientName = $("input[name=patientName]").val();
//                    var doctorName = $("input[name=doctorName]").val();
//                    var hospitalName = $("input[name=hospitalName]").val();
                    var note = $("input[name=note]").val();
//                    var needInvoice = $("select[name=needInvoice]").val();
//                    var invoiceName = $("input[name=invoiceName]").val();
//                    var invoiceNumber = $("input[name=invoiceNumber]").val();
//                    var invoiceDetail = $("input[name=invoiceDetail]").val();

                    var data = {};

//                    if(number == 0) {
//                        alert("请选择规格");
//                        return false;
//                    }
                    if(isNullOrEmpty(size)) {
                        alert("请选择型号");
                        return false;
                    }
                    if (isNullOrEmpty(patientName)) {
                        alert("请填写患者姓名");
                        return false;
                    }

//                    if (isNullOrEmpty(doctorName)) {
//                        alert("请填写医生姓名");
//                        return false;
//                    }
//
//                    if (isNullOrEmpty(hospitalName)) {
//                        alert("请填写医院名称");
//                        return false;
//                    }

                    if(isNullOrEmpty(receiveName)) {
                        alert("请填写收件人姓名");
                        return false;
                    }
                    if(isNullOrEmpty(receiveAddress)) {
                        alert("请填写收件人地址");
                        return false;
                    }
                    if(isNullOrEmpty(receiveContact)) {
                        alert("请填写收件人电话");
                        return false;
                    }
                    if(!checkPhone(receiveContact)) {
                        alert("手机号位数不对");
                        return false;
                    }
//                    if(needInvoice != -1) {
//                        if(needInvoice == 1) {
//                            if (isNullOrEmpty(invoiceName)) {
//                                alert("请填写发票抬头");
//                                return false;
//                            }
//                            if (isNullOrEmpty(invoiceNumber)) {
//                                alert("请填写纳税人识别号");
//                                return false;
//                            }
//                        }
//                    }
//                    if(needInvoice != -1) {
//                        if(isNullOrEmpty(invoiceDetail)) {
//                            alert("请填写发票明细");
//                            return false;
//                        }
//                    }
                    data.status = status;
                    data.productId = productId;
                    data.orderId = "{$orderId}";;
                    data.size = size;
                    data.number = app.number;
                    data.productId = productId;
                    data.receiveName = receiveName;
                    data.receiveContact = receiveContact;
                    data.receiveAddress = receiveAddress;
                    data.patientName = patientName;
//                    data.patientSex = patientSex;
//                    data.patientAge = patientAge;
//                    data.doctorName = doctorName;
//                    data.hospitalName = hospitalName;
                    data.note = note;
//                    data.needInvoice = needInvoice;
//                    data.invoiceName = invoiceName;
//                    data.invoiceNumber = invoiceNumber;

                    if(status == -2){
                        if(confirm("请确认是否提交团购预订？")){
                            $.ajax({
                                url:"/wechat/order/createGroupOrder",
                                type:"post",
                                data:data,
                                dataType:"JSON",
                                beforeSend:function(){
                                    $("#loadingToast").show();
                                },
                                complete:function(){
                                    $('#loadingToast').hide();
                                },
                                success:function(data){
                                    if(data.code != 200) {
                                        alert(data.msg);
                                        return false;
                                    }
                                    window.location.href = "/wechat/userCenter/myOrder?status=-2";
                                },
                            })
                        }else{
                            return;
                        }
					}
                    if(status == -1 || status == 1){
                        if(confirm("请确认是否提交订单？")){
                            $.ajax({
                                url:"/wechat/order/createGroupOrder",
                                type:"post",
                                data:data,
                                dataType:"JSON",
                                beforeSend:function(){
                                    $("#loadingToast").show();
                                },
                                complete:function(){
                                    $('#loadingToast').hide();
                                },
                                success:function(data){
                                    if(data.code != 200) {
                                        alert(data.msg);
                                        return false;
                                    }
                                    window.location.href = "/wechat/userCenter/payInfo/id/"+data.order_id;
                                },
                                error:function(data){
                                    alert(data.order_id);
                                    return false;
                                }
                            })
                        }else{
                            return;
                        }
                    }

                }
            }
        })


        $(".item select").change(function() {
            var value = $(this).find("option:selected").text();
            $(this).prev().val(value);
        });

        $("select[name=needInvoice]").change(function() {
            if($(this).val() == 1) {
                $(".item.invoice").show();
            } else {
                $(".item.invoice").hide();
            }
            if($(this).val() == -1) {
                $(".item.invoiceDetail").hide();
            } else {
                $(".item.invoiceDetail").show();
            }
            if($(this).val() == 2) {
                $(".item.invoiceName").show();
                $("input[name=invoiceName]").val($("input[name=patientName]").val());
            }
        });

        $("img.icon-up").click(function() {

            $(this).hide();
            $("img.icon-down").show();

            $(".size-detail").toggle();
            $(".size-comment").toggle();

        });

        $("img.icon-down").click(function() {

            $(this).hide();
            $("img.icon-up").show();

            $(".size-detail").toggle();
            $(".size-comment").toggle();
        });

        $("select[name=size]").change(function() {
            if($("select[name=size]").val() == ""){
                app.number = 0;
            }else{
                app.number = 1;
			}
        });

        $("select[name=size]").append("<option value=''></option>");
        var sizeArr = "{$product.size}".split("/");

        for(var i=0;i<sizeArr.length;i++){
            if(sizeArr[i] == "{$groupOrder.size}"){
                $("select[name=size]").prev().val(sizeArr[i]);
                $("select[name=size]").append("<option value='"+sizeArr[i]+"' selected='selected'>" + sizeArr[i] + "</option>");
			}else{
                $("select[name=size]").append("<option value='"+sizeArr[i]+"'>" + sizeArr[i] + "</option>");
			}
        }

        if(!isNullOrEmpty("{$groupOrder.need_invoice}")){
            $("select[name=needInvoice]").val("{$groupOrder.need_invoice}");
		}
        var value = $("select[name=needInvoice]").find("option:selected").text();
        $("select[name=needInvoice]").prev().val(value);

        if($("select[name=needInvoice]").val() == 1) {
            $(".item.invoice").show();
        } else {
            $(".item.invoice").hide();
        }
        if($("select[name=needInvoice]").val() == -1) {
            $(".item.invoiceDetail").hide();
        } else {
            $(".item.invoiceDetail").show();
        }
    })

</script>

<div class="container" id="container">
	<!--input type="hidden" name="couponCode" value="{$coupon.coupon_code}" /-->
	<div class="product-detail">
		<img class="product-img" src="{$product.image_url}" alt="product">
		<div class="detail-info">
			<p class="product-price">原价：￥{$product.price}</p>

			<p class="product-name" style="font-weight: bold;">{$product.product_name}</p>

			<p style="color: #de7d74; font-weight:bold; float: right" id="productPrice">团购价：￥{$product.group_price}</p>

			<!--p class="product-size" style="color: #45a1de">【{$coupon.size}】码</p-->
			<p class="buy-time" style="font-size: 0.8rem">截止日期：{$product.expiry_date}</p>
		</div>
	</div>
	<div class="example" style="height: 10rem; background-color: white">
		<!--img class="hint-info" src="/Template/images/icon-hint.png" alt="">
		<span class="title" style="color: #00a0e9">胸围尺寸对应型号测量示例</span-->
		<div>
			<div class="example-detail" style="float: left">
				{$product.measure_description}
			</div>
			<img style="height: 9.5rem;width: auto; float: right" src="{$product.measure_image}" alt="bg">
		</div>
	</div>

	<div class="product-need" style="margin-bottom: 0">
		<div class="item">
			<span>型号</span>
			<input type="text" value="请选择型号" name="size" readonly placeholder="">
			<select name="size" class="size">
			</select>
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
	</div>
	<div class="patient-info agent">
		<div class="item">
			<span>患者姓名</span>
			<input type="text" name="patientName" placeholder="请填写患者姓名" value="{$groupOrder.patient_name}">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
		<input type="hidden" name="needPatient">
	</div>
	<!--div class="doctor-info agent">
        <div class="item">
            <span>医生</span>
            <input type="text" name="doctorName" value="{$coupon.default_doctor_name}" placeholder="">
            <img class="icon-right" src="/Template/images/icon-right.png" alt="">
        </div>
        <div class="item">
            <span>医院</span>
            <input type="text" name="hospitalName" value="{$coupon.default_hospital_name}" placeholder="">
            <img class="icon-right" src="/Template/images/icon-right.png" alt="">
        </div>
    </div-->
	<div class="patient-info">
		<div class="item ">
			<span>收件人姓名</span>
			<input type="text" name="receiveName" placeholder="请填写收件人姓名" value="{$groupOrder.receive_name}">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
		<div class="item ">
			<span>收件人电话</span>
			<input type="text" name="receiveContact" placeholder="请填写收件人电话" value="{$groupOrder.receive_contact}">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
		<div class="item ">
			<span>收件地址</span>
			<input type="text" name="receiveAddress" placeholder="请填写收件地址" value="{$groupOrder.receive_address}">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
	</div>
	<!--div class="product-need" style="margin-bottom: 0">
		<div class="item">
			<span>是否开发票</span>
			<input type="text" value="不开发票" name="needInvoice" readonly placeholder="">
			<select name="needInvoice" class="invoice-choose">
				<option value="-1" selected="selected">不开发票</option>
				<option value="1">公司发票</option>
				<option value="2">个人发票</option>
			</select>
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
		<div class="item invoice invoiceName" style="display: none;">
			<span>发票抬头</span>
			<input name="invoiceName" type="text" placeholder="请填写发票抬头" value="{$groupOrder.invoice_name}">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
		<div class="item invoice" style="display: none;">
			<span>纳税人识别号</span>
			<input name="invoiceNumber" type="text" placeholder="请填纳税人识别号" value="{$groupOrder.invoice_number}">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
		<div class="item invoiceDetail" style="display: none;">
			<span>发票明细</span>
			<input name="invoiceDetail" type="text" placeholder="请填写发票明细">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
	</div-->
	<div class="address-info" style="margin-bottom: 1rem">
		<div class="item">
			<span>留言备注</span>
			<input type="text" name="note" placeholder="例如发票信息等" value="{$groupOrder.note}">
			<img class="icon-right" src="/Template/images/icon-right.png" alt="">
		</div>
	</div>
	<div class="order-operation">
		<if condition="$product['group_status'] eq -1 && $groupOrder['number'] eq 0">
			<p style="margin-left: 20%;width: 40%">共<a style="color: #e97a15"> {{number}} </a>件</p>
			<button id="submitBtn" class="submit-order" v-on:click="createOrder(-2)">提交预订</button>
		</if>
		<if condition="$product['group_status'] eq -1 && $groupOrder['number'] neq 0">
			<p style="margin-left: 20%;width: 40%">已预订<a style="color: #e97a15"> {{number}} </a>件</p>
		</if>
		<if condition="$product['group_status'] eq 1 && $groupOrder['status'] eq '-2'">
			<p style="margin-left: 20%;width: 40%">共<a style="color: #e97a15"> {{number}} </a>件,合计：<span>￥{{number*singlePrice}}</span> </p>
			<button id="submitBtn" class="submit-order" v-on:click="createOrder(-1)">付 款</button>
		</if>
		<if condition="$product['group_status'] eq 1 && $status eq '1' && $groupOrder['number'] eq 0">
			<p style="margin-left: 20%;width: 40%">共<a style="color: #e97a15"> {{number}} </a>件,合计：<span>￥{{number*singlePrice}}</span> </p>
			<button id="submitBtn" class="submit-order" v-on:click="createOrder(1)">付 款</button>
		</if>
		<if condition="$product['group_status'] eq 1 && $groupOrder['number'] neq 0">
			<p style="margin-left: 20%;width: 40%">已购买<a style="color: #e97a15"> {{number}} </a>件</p>
		</if>
	</div>
	<!--if condition="$customer['subscribe'] neq 1">
		<div class="subscribe">
			<div class="pop-frame">
				<div class="hint">
					<div class="line"></div>
					<p class="rec-title">无法识别二维码?</p>
					<ul>
						<li>1、打开微信,点击添加朋友</li>
						<li>2、搜索微信号:xwkkffj</li>
						<li>3、点击”关注”,完成</li>
					</ul>
				</div>
			</div>
			<div class="two-d-code">
				<img class="two-d-code-bg" src="/Template/images/doc-2d-code-bg.png" alt="">
				<img class="two-d-code-img" src="/Template/images/xwk-qrcode.jpg" alt="">
				<p class="recognize">
					长按图片[识别二维码]关注公众号
				</p>
			</div>
		</div>
	</if-->
</div>
<include file="./Template/footer.html" />